package com.yuandian.management.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuandian.api.management.entity.ConfCustomExclusiveIndicator;
import com.yuandian.api.management.validate.UpdateFlag;
import com.yuandian.bpm.common.core.util.R;
import com.yuandian.bpm.common.log.annotation.SysLog;
import com.yuandian.management.service.ConfCustomExclusiveIndicatorService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * 自定义专属指标字段表-Controller
 * @author zfsn
 * @date 2023-6-7
 */
@Api(tags = "专属指标自定义")
@RestController
@RequestMapping("/customExclusiveIndicator")
public class ConfCustomExclusiveIndicatorController {

	@Autowired
	private ConfCustomExclusiveIndicatorService confCustomExclusiveIndicatorService;

	/**
	 * 通过主键查询数据
	 * @param idList 主键集合
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "通过主键查询数据", notes = "通过主键查询数据，支持批量查询")
	@GetMapping("/{ids}")
	public R<List<ConfCustomExclusiveIndicator>> queryByIds(@PathVariable("ids") List<Integer> idList) {
		return R.ok(confCustomExclusiveIndicatorService.listByIds(idList));
	}

	/**
	 * 分页查询
	 * @param confCustomExclusiveIndicator 筛选条件
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "分页查询", notes = "分页查询")
	@PostMapping
	@ApiImplicitParams({
			@ApiImplicitParam(name = "indicatorMappingName", value = "标识中文(支持模糊查询)", paramType = "body", required = true, dataType = "String"),
			@ApiImplicitParam(name = "indicatorName", value = "标识名称(支持模糊查询)", paramType = "body", required = true, dataType = "String"),
			@ApiImplicitParam(name = "pageSize", value = "每页大小", paramType = "body", required = true, dataType = "Integer"),
			@ApiImplicitParam(name = "pageNum", value = "当前页数", paramType = "body", required = true, dataType = "Integer"),
	})
	public R<Page<ConfCustomExclusiveIndicator>> page(@RequestBody @ApiIgnore ConfCustomExclusiveIndicator confCustomExclusiveIndicator) {
		return R.ok(confCustomExclusiveIndicatorService.listPage(confCustomExclusiveIndicator));
	}

	/**
	 * 新增数据
	 * @param confCustomExclusiveIndicator 实例对象
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "新增数据", notes = "新增数据")
	@SysLog("新增自定义专属指标字段表数据")
	@PostMapping("/save")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "indicatorMappingName", value = "标识中文", paramType = "body", required = true, dataType = "String"),
			@ApiImplicitParam(name = "indicatorName", value = "标识名称", paramType = "body", required = true, dataType = "String"),
			@ApiImplicitParam(name = "isShow", value = "是否展示： 0 为不展示， 1为展示", paramType = "body", required = true, dataType = "Integer"),
	})
	public R<String> save(@RequestBody @ApiIgnore ConfCustomExclusiveIndicator confCustomExclusiveIndicator) {
		return confCustomExclusiveIndicatorService.saveData(confCustomExclusiveIndicator);
	}

	/**
	 * 通过主键更新数据
	 * @param confCustomExclusiveIndicator 实例对象
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "通过主键更新数据", notes = "通过主键更新数据")
	@SysLog("更新自定义专属指标字段表数据")
	@PutMapping
	@ApiImplicitParams({
			@ApiImplicitParam(name = "id", value = "id", paramType = "body", required = true, dataType = "Integer"),
			@ApiImplicitParam(name = "indicatorMappingName", value = "标识中文", paramType = "body", required = true, dataType = "String"),
			@ApiImplicitParam(name = "indicatorName", value = "标识名称", paramType = "body", required = true, dataType = "String"),
			@ApiImplicitParam(name = "isShow", value = "是否展示： 0 为不展示， 1为展示", paramType = "body", required = true, dataType = "Integer"),
	})
	public R<String> updateById(@RequestBody @ApiIgnore @Validated(UpdateFlag.class) ConfCustomExclusiveIndicator confCustomExclusiveIndicator) {
		return confCustomExclusiveIndicatorService.updateDataById(confCustomExclusiveIndicator);
	}

	/**
	 * 通过主键删除数据
	 * @param ids 主键
	 * @return 通用返回对象
	 */
	@ApiOperation(value = "通过主键删除数据", notes = "通过主键删除数据")
	@DeleteMapping("delete/{ids}")
	public R<Boolean> removeByIds(@PathVariable("ids") List<Integer> ids) {
		return R.ok(confCustomExclusiveIndicatorService.removeByIds(ids));
	}

}